Skip to content

feat(errors): surface rate-limit headers on HTTP 429 failures - #763

Merged
platinummonkey merged 3 commits into
mainfrom
feat/rate-limit-error-reporting
Aug 26, 2026
Merged

feat(errors): surface rate-limit headers on HTTP 429 failures#763
platinummonkey merged 3 commits into
mainfrom
feat/rate-limit-error-reporting

Conversation

@platinummonkey

Copy link
Copy Markdown
Collaborator

Summary

  • Captures Datadog X-RateLimit-* response headers from typed SDK commands (via middleware), raw HTTP helpers, and pup api
  • On HTTP 429, prints readable rate-limit details (rule name, limit, remaining, period, reset) to stderr with a retry hint
  • Exits with code 429 so automation can distinguish rate-limit failures from other errors

Closes #747

Changes

  • src/rate_limit.rs — header extraction, formatting, exit-code selection, and unit tests
  • src/client.rsRateLimitCaptureMiddleware on the SDK reqwest client
  • src/raw_client.rsHttpError.rate_limit field populated from response headers; integration test with mock 429
  • src/main.rs — central CLI error handler prints enhanced 429 output and exits 429
  • src/commands/api.rs — store rate-limit headers before failing non-2xx responses

Example output

Error: failed to list monitors: error in response: status code 429 Too Many Requests
Rate limit details:
  rule: get_all_monitors
  limit: 1000
  remaining: 0
Hint: rate limited — wait and retry

Test plan

  • cargo test rate_limit
  • cargo test test_raw_get_rate_limit_includes_headers
  • cargo clippy -- -D warnings
  • cargo fmt --check

Made with Cursor

Typed SDK commands discard response headers, leaving automation blind to
which Datadog rate-limit rule triggered a 429. Capture X-RateLimit-* via
SDK middleware and raw HTTP helpers, print readable rule/limit/remaining
details on stderr, and exit with code 429.

Closes #747

Co-authored-by: Cursor <cursoragent@cursor.com>
@platinummonkey
platinummonkey requested a review from a team as a code owner August 25, 2026 17:09
When --verbose is set, successful typed commands emit captured
X-RateLimit-* metadata to stderr using the same format as --output
(json, yaml, table, csv, tsv), including the agent-mode JSON envelope.

Co-authored-by: Cursor <cursoragent@cursor.com>
@datadog-prod-us1-6

This comment has been minimized.

Browser WASM compiles formatter via lib.rs, which does not include the
rate_limit module. Skip verbose rate-limit printing in browser builds.

Co-authored-by: Cursor <cursoragent@cursor.com>
@platinummonkey
platinummonkey merged commit 54eaf6a into main Aug 26, 2026
6 checks passed
@platinummonkey
platinummonkey deleted the feat/rate-limit-error-reporting branch August 26, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Expose response headers (esp. X-RateLimit-* metadata) on typed subcommands

2 participants